package com.example.biyesheji.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.biyesheji.model.param.MenuTableParam;
import com.example.biyesheji.model.param.ProductSaleParam;
import com.example.biyesheji.model.result.ProductSaleResult;
import com.example.biyesheji.pojo.ProductSales;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import javax.validation.constraints.Max;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Mapper
public interface ProductMapper{

    @Select("select * from productsales limit 1,5")
    List<ProductSales> getProductList();


    /**
     * @Params
     * @Return @return {@link List }<{@link ProductSales }>
     * @Description 得到一列
     * @Throws
     * @Author xwh
     * @Date 2023/02/08
     */
    @Select("select * from productsales limit #{flag} , 1")
    List<ProductSales> getOneColumn(Long flag);


    /**
     * @Params @param flag id
     * @Return @return {@link List }<{@link Float }>
     * @Description 得到一个价格
     * @Throws
     * @Author xwh
     * @Date 2023/02/08
     */

    @Select("select price from productsales where id = #{flag}")
    List<Float> getOnePrice(Long flag);

    @Select("select category_code from productsales where id = #{flag}")
    List<String> getCategory(Long flag);

    //获取所有商品
    @Select("select category_code from productsales")
    List<String> getcategoryCodeList();

    //获取所有价格
    @Select("select price from productsales")
    List<Float> getToalPrice();

    @Select("select age from productsales")
    List<Integer> getAgeList();

    @Select("select count(*) from productsales")
    Long orderQuenty();

    //主页一
    @Select("select user_id,price,brand,category_code ,event_time from productsales order by id desc ")
    List<ProductSales> newRecodeLsit();

    @Select("select brand,count(*) AS total from productsales GROUP BY brand ORDER BY total DESC")
    List<ProductSaleResult> getMenuTable();

    @Select("select price from productsales where brand = #{item2}")
    List<String> itemList(@Param("item2") String str2);

    @Select("select event_time from productsales limit 1,101")
    List<String> timeList();


    /**
     * @Params
     * @Return @return {@link List }<{@link String }>
     * @Description
     * @Throws
     * @Author xwh
     * @Date 2023/02/12
     *///主页二
    @Select("select event_time,price from productsales limit 1,10")
    List<ProductSales> getEPl();



    @Select("select * from sales")
    List<ProductSales> getBrandEBP();


    @Select("select brand,count(*) AS total from productsales GROUP BY brand ORDER BY total DESC LIMIT 0,8")
    List<String> getBrandList();


    /**
     * @Params @param userId 用户id
     * @Return @return {@link List }<{@link ProductSales }>
     * @Description 通过用户id查询数据
     * @Throws
     * @Author xwh
     * @Date 2023/02/16
     */
    @Select("select event_time,user_id,brand,sum(price) as price from sales where user_id = #{userId} GROUP BY brand ORDER BY price DESC")
    List<ProductSales> getByUserId(@Param("userId") String userId);




    @Select("select event_time,user_id,brand,price from sales where user_id = #{userId}")
    List<ProductSales> getmoreInfo(@Param("userId") String userId);


    //查询表格分页数据
    @Select("<script>"+
            "select * from sales"+
            "<where>"+
            "<if test ='param.userId != null'>"+
            "user_id = #{param.userId}"+
            "</if>"+
            "<if test ='param.orderId != null'>"+
            "user_id = #{param.orderId}"+
            "</if>"+
            "<if test ='param.productId != null'>"+
            "user_id = #{param.productId}"+
            "</if>"+
            "</where>"+
            "limit #{param.page},"+
            "#{param.limit}"+
    "</script>")
    List<ProductSales> getSearchProductSales(@Param("param") ProductSaleParam param );





}
